//
//  MineViewController.m
//  半糖
//
//  Created by RenShuang on 15-9-1.
//  Copyright (c) 2015年 shuang. All rights reserved.
//

#import "MineViewController.h"
#import "BaseHeader.h"

@interface MineViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property(nonatomic,retain)UICollectionView *searchCollection;
@property(nonatomic,retain)NSArray *titleArr;

@end

@implementation MineViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    [self.searchCollection reloadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.title = @"分类";
    
    //改变navigationBar上title的颜色,大小,字体等
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor, [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.6],UITextAttributeTextShadowColor,[UIFont fontWithName:@"Marion-Italic" size:22.0],UITextAttributeFont,nil]];
    
    self.view.backgroundColor = [UIColor yellowColor];
    _titleArr = [[NSArray alloc] initWithObjects:@"家居",@"创意",@"办公",@"卫浴",@"护肤",@"美食",@"主题",@"植物",@"厨具",@"杂货",@"运动",@"数码", nil];
    [self createCollectionView];

    
    
    
}

- (void)createCollectionView
{
    //flowLayOut不用release
    UICollectionViewFlowLayout *flowLayOut = [[UICollectionViewFlowLayout alloc] init];
    flowLayOut.itemSize = CGSizeMake(SCREEN_WIDTH/2 - 6, SCREEN_HEIGHT/6);
    flowLayOut.minimumInteritemSpacing = 1;
    flowLayOut.minimumLineSpacing = 1;
    flowLayOut.scrollDirection = UICollectionViewScrollDirectionVertical;
    flowLayOut.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    
    
    self.searchCollection = [[UICollectionView alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT-30) collectionViewLayout:flowLayOut];
    self.searchCollection.delegate = self;
    self.searchCollection.dataSource = self;
    self.searchCollection.backgroundColor = [UIColor colorWithRed:240/255. green:240/255. blue:240/255. alpha:1];
    [self.view addSubview:_searchCollection];
    [_searchCollection release];
    
    
    [self.searchCollection registerClass:[searchCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 12;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    searchCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    NSArray *eArr = @[@"Home",@"Originality",@"Office",@"Bathroom",@"Skin Care",@"Food",@"Theme",@"Plant",@"Kitchen",@"Groceries",@"Sports",@"Digital"];
    NSArray *picArr = @[@"家居.jpg",@"创意.jpg",@"办公.jpg",@"卫浴.jpg",@"护肤.jpg",@"美食.jpg",@"主题.jpg",@"植物.jpg",@"厨具.jpg",@"杂货.jpg",@"运动.jpg",@"数码.jpg"];
    cell.cLabel.text = [_titleArr objectAtIndex:indexPath.row];
    cell.eLabel.text = [eArr objectAtIndex:indexPath.row];
    cell.myImageView.image = [UIImage imageNamed:[picArr objectAtIndex:indexPath.row]];
    cell.contentView.backgroundColor = [NightHandle shareHandle].viewColor;
    cell.cLabel.textColor = [NightHandle shareHandle].wordColor;
    cell.eLabel.textColor = [NightHandle shareHandle].wordColor;
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    ZhuanTiViewController *zt = [[ZhuanTiViewController alloc] init];
    zt.title = [_titleArr objectAtIndex:indexPath.row];
    zt.number = indexPath.row + 1;
    if (indexPath.row >= 6) {
        zt.number = indexPath.row + 2;
    }
    if (indexPath.row >= 9) {
        zt.number = indexPath.row + 3;
    }
    [self.navigationController pushViewController:zt animated:YES];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
